home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_emacs.idb / usr / freeware / info / emacs-12.z / emacs-12 (.txt)
GNU Info File  |  1998-10-27  |  50KB  |  916 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.63 from the
  2. input file emacs.texi.
  3. File: emacs,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Program Indent
  4. Indenting Several Lines
  5. -----------------------
  6.    When you wish to re-indent several lines of code which have been
  7. altered or moved to a different level in the list structure, you have
  8. several commands available.
  9. `C-M-q'
  10.      Re-indent all the lines within one list (`indent-sexp').
  11. `C-u TAB'
  12.      Shift an entire list rigidly sideways so that its first line is
  13.      properly indented.
  14. `C-M-\'
  15.      Re-indent all lines in the region (`indent-region').
  16.    You can re-indent the contents of a single list by positioning point
  17. before the beginning of it and typing `C-M-q' (`indent-sexp' in Lisp
  18. mode, `indent-c-exp' in C mode; also bound to other suitable commands
  19. in other modes).  The indentation of the line the sexp starts on is not
  20. changed; therefore, only the relative indentation within the list, and
  21. not its position, is changed.  To correct the position as well, type a
  22. TAB before the `C-M-q'.
  23.    If the relative indentation within a list is correct but the
  24. indentation of its first line is not, go to that line and type `C-u
  25. TAB'.  TAB with a numeric argument reindents the current line as usual,
  26. then reindents by the same amount all the lines in the grouping
  27. starting on the current line.  In other words, it reindents the whole
  28. grouping rigidly as a unit.  It is clever, though, and does not alter
  29. lines that start inside strings, or C preprocessor lines when in C mode.
  30.    Another way to specify the range to be re-indented is with the
  31. region.  The command `C-M-\' (`indent-region') applies TAB to every
  32. line whose first character is between point and mark.
  33. File: emacs,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Program Indent
  34. Customizing Lisp Indentation
  35. ----------------------------
  36.    The indentation pattern for a Lisp expression can depend on the
  37. function called by the expression.  For each Lisp function, you can
  38. choose among several predefined patterns of indentation, or define an
  39. arbitrary one with a Lisp program.
  40.    The standard pattern of indentation is as follows: the second line
  41. of the expression is indented under the first argument, if that is on
  42. the same line as the beginning of the expression; otherwise, the second
  43. line is indented underneath the function name.  Each following line is
  44. indented under the previous line whose nesting depth is the same.
  45.    If the variable `lisp-indent-offset' is non-`nil', it overrides the
  46. usual indentation pattern for the second line of an expression, so that
  47. such lines are always indented `lisp-indent-offset' more columns than
  48. the containing list.
  49.    The standard pattern is overridden for certain functions.  Functions
  50. whose names start with `def' always indent the second line by
  51. `lisp-body-indent' extra columns beyond the open-parenthesis starting
  52. the expression.
  53.    The standard pattern can be overridden in various ways for individual
  54. functions, according to the `lisp-indent-function' property of the
  55. function name.  There are four possibilities for this property:
  56. `nil'
  57.      This is the same as no property; the standard indentation pattern
  58.      is used.
  59. `defun'
  60.      The pattern used for function names that start with `def' is used
  61.      for this function also.
  62. a number, NUMBER
  63.      The first NUMBER arguments of the function are "distinguished"
  64.      arguments; the rest are considered the "body" of the expression.
  65.      A line in the expression is indented according to whether the
  66.      first argument on it is distinguished or not.  If the argument is
  67.      part of the body, the line is indented `lisp-body-indent' more
  68.      columns than the open-parenthesis starting the containing
  69.      expression.  If the argument is distinguished and is either the
  70.      first or second argument, it is indented *twice* that many extra
  71.      columns.  If the argument is distinguished and not the first or
  72.      second argument, the standard pattern is followed for that line.
  73. a symbol, SYMBOL
  74.      SYMBOL should be a function name; that function is called to
  75.      calculate the indentation of a line within this expression.  The
  76.      function receives two arguments:
  77.     STATE
  78.           The value returned by `parse-partial-sexp' (a Lisp primitive
  79.           for indentation and nesting computation) when it parses up to
  80.           the beginning of this line.
  81.     POS
  82.           The position at which the line being indented begins.
  83.      It should return either a number, which is the number of columns of
  84.      indentation for that line, or a list whose car is such a number.
  85.      The difference between returning a number and returning a list is
  86.      that a number says that all following lines at the same nesting
  87.      level should be indented just like this one; a list says that
  88.      following lines might call for different indentations.  This makes
  89.      a difference when the indentation is being computed by `C-M-q'; if
  90.      the value is a number, `C-M-q' need not recalculate indentation
  91.      for the following lines until the end of the list.
  92. File: emacs,  Node: C Indent,  Next: Custom C Indent,  Prev: Lisp Indent,  Up: Program Indent
  93. Commands for C Indentation
  94. --------------------------
  95.    Here are the commands for indentation in C mode and related modes:
  96. `C-c C-q'
  97.      Reindent the current top-level function definition or aggregate
  98.      type declaration (`c-indent-defun').
  99. `C-M-q'
  100.      Reindent each line in the balanced expression that follows point
  101.      (`c-indent-exp').  A prefix argument inhibits error checking and
  102.      warning messages about invalid syntax.
  103. `TAB'
  104.      Reindent the current line, and/or in some cases insert a tab
  105.      character (`c-indent-command').
  106.      If `c-tab-always-indent' is `t', this command always reindents the
  107.      current line and does nothing else.  This is the default.
  108.      If that variable is `nil', this command reindents the current line
  109.      only if point is at the left margin or in the line's indentation;
  110.      otherwise, it inserts a tab.
  111.      Any other value (not `nil' or `t') means always reindent the line,
  112.      and also insert a tab if within a comment, a string, or a
  113.      preprocessor directive.
  114. `C-u TAB'
  115.      Reindent the current line according to its syntax; also rigidly
  116.      reindent any other lines of the expression that starts on the
  117.      current line.  *Note Multi-line Indent::.
  118.    To reindent the whole current buffer, type `C-x h C-M-\'.  This
  119. first selects the whole buffer as the region, then reindents that
  120. region.
  121.    To reindent the current block, use `C-M-u C-M-q'.  This moves to the
  122. front of the block and then reindents it all.
  123. File: emacs,  Node: Custom C Indent,  Prev: C Indent,  Up: Program Indent
  124. Customizing C Indentation
  125. -------------------------
  126.    C mode and related modes use a simple yet flexible mechanism for
  127. customizing indentation.  The mechanism works in two steps: first it
  128. classifies the line syntactically according to its contents and context;
  129. second, it associates each kind of syntactic construct with an
  130. indentation offset which you can customize.
  131. * Menu:
  132. * Syntactic Analysis::
  133. * Indentation Calculation::
  134. * Changing Indent Style::
  135. * Syntactic Symbols::
  136. * Variables for C Indent::
  137. * C Indent Styles::
  138. File: emacs,  Node: Syntactic Analysis,  Next: Indentation Calculation,  Up: Custom C Indent
  139. Step 1--Syntactic Analysis
  140. ..........................
  141.    In the first step, the C indentation mechanism looks at the line you
  142. are currently indenting and determines the syntactic components of the
  143. construct on that line.  It builds a list of these syntactic components,
  144. where each component on the list contains a "syntactic symbol" and a
  145. relative buffer position.  Syntactic symbols describe grammatical
  146. elements such as STATEMENT, SUBSTATEMENT, CLASS-OPEN, CLASS-CLOSE,
  147. KNR-ARGDECL, etc.
  148.    Conceptually, a line of C code is always indented relative to the
  149. indentation of some line higher up in the buffer.  This is represented
  150. by the relative buffer positions in the syntactic component list.
  151.    Here is an example.  Suppose we have the following code in a C++ mode
  152. buffer (the line numbers don't actually appear in the buffer):
  153.      1: void swap (int& a, int& b)
  154.      2: {
  155.      3:   int tmp = a;
  156.      4:   a = b;
  157.      5:   b = tmp;
  158.      6: }
  159.    If you type `C-c C-s' (which runs the command
  160. `c-show-syntactic-information') on line 4, it shows the result of the
  161. indentation mechanism for that line:
  162.      ((statement . 32))
  163.    This indicates that the line is a statement and it is indented
  164. relative to buffer position 32, which happens to be the `i' in `int' on
  165. line 3.  If you move the cursor to line 3 and type `C-c C-s', it
  166. displays this:
  167.      ((defun-block-intro . 28))
  168.    This indicates that the `int' line is the first statement in a
  169. block, and is indented relative to buffer position 28, which is the
  170. brace just after the function header.
  171. Here is another example:
  172.      1: int add (int val, int incr, int doit)
  173.      2: {
  174.      3:   if (doit)
  175.      4:     {
  176.      5:       return (val + incr);
  177.      6:     }
  178.      7:   return (val);
  179.      8: }
  180. Typing `C-c C-s' on line 4 displays this:
  181.      ((substatement-open . 43))
  182.    This says that the brace *opens* a substatement block.  By the way,
  183. a "substatement" indicates the line after an `if', `else', `while',
  184. `do', `switch', and `for' statements.
  185.    After a line has been analyzed syntactically for indentation, the
  186. global variable `c-syntactic-context' contains a list that describes
  187. the results.  Each element in this list is a a "syntactic component": a
  188. cons cell containing a syntactic symbol and (optionally) its
  189. corresponding buffer position.  There may be several elements in a
  190. component list; typically only one element has a buffer position.
  191. File: emacs,  Node: Indentation Calculation,  Next: Changing Indent Style,  Prev: Syntactic Analysis,  Up: Custom C Indent
  192. Step 2--Indentation Calculation
  193. ...............................
  194.    The C indentation mechanism calculates the indentation for the
  195. current line using the list of syntactic components,
  196. `c-syntactic-context', derived from syntactic analysis.  Each component
  197. is a cons cell that contains a syntactic symbol and may also contain a
  198. pointer to a location in the buffer.
  199.    Each component contributes to the final total indentation of the line
  200. in two ways.  First, the syntactic symbol identifies an element of
  201. `c-offsets-alist', which is an association list mapping syntactic
  202. symbols into indentation offsets.  Each syntactic symbol's offset adds
  203. to the total indentation.  Second, if the component includes a buffer
  204. position, the column number of that position adds to the indentation.
  205. All these offsets and column numbers, added together, give the total
  206. indentation.
  207.    The following examples demonstrate the workings of the C indentation
  208. mechanism:
  209.      1: void swap (int& a, int& b)
  210.      2: {
  211.      3:   int tmp = a;
  212.      4:   a = b;
  213.      5:   b = tmp;
  214.      6: }
  215.    Suppose that point is on line 3 and you type TAB to reindent the
  216. line.  As explained above (*note Syntactic Analysis::.), the syntactic
  217. component list for that line is:
  218.      ((defun-block-intro . 28))
  219.    In this case, the indentation calculation first looks up
  220. `defun-block-intro' in the `c-offsets-alist' alist.  Suppose that it
  221. finds the integer 2; it adds this to the running total (initialized to
  222. zero), yielding a updated total indentation of 2 spaces.
  223.    The next step is to find the column number of buffer position 28.
  224. Since the brace at buffer position 28 is in column zero, this adds 0 to
  225. the running total.  Since this line has only one syntactic component,
  226. the total indentation for the line is 2 spaces.
  227.      1: int add (int val, int incr, int doit)
  228.      2: {
  229.      3:   if (doit)
  230.      4:     {
  231.      5:       return(val + incr);
  232.      6:     }
  233.      7:   return(val);
  234.      8: }
  235.    If you type TAB on line 4, the same process is performed, but with
  236. different data.  The syntactic component list for this line is:
  237.      ((substatement-open . 43))
  238.    Here, the indentation calculation's first job is to look up the
  239. symbol `substatement-open' in `c-offsets-alist'.  Let's assume that the
  240. offset for this symbol is 2.  At this point the running total is 2 (0 +
  241. 2 = 2).  Then it adds the column number of buffer position 43, which is
  242. the `i' in `if' on line 3.  This character is in column 2 on that line.
  243. Adding this yields a total indentation of 4 spaces.
  244.    If a syntactic symbol in the analysis of a line does not appear in
  245. `c-offsets-alist', it is ignored; if in addition the variable
  246. `c-strict-syntax-p' is non-`nil', it is an error.
  247. File: emacs,  Node: Changing Indent Style,  Next: Syntactic Symbols,  Prev: Indentation Calculation,  Up: Custom C Indent
  248. Changing Indentation Style
  249. ..........................
  250.    There are two ways to customize the indentation style for the C
  251. modes.  First, you can select one of several predefined styles, each of
  252. which specifies offsets for all the syntactic symbols.  For more
  253. flexibility, you can customize the handling of individual syntactic
  254. symbols.  *Note Syntactic Symbols::, for a list of all defined
  255. syntactic symbols.
  256. `M-x c-set-style RET STYLE RET'
  257.      Select predefined indentation style STYLE.  Type `?' when entering
  258.      STYLE to see a list of supported styles; to find out what a style
  259.      looks like, select it and reindent some C code.
  260. `C-c C-o SYMBOL RET OFFSET RET'
  261.      Set the indentation offset for syntactic symbol SYMBOL
  262.      (`c-set-offset').  The second argument OFFSET specifies the new
  263.      indentation offset.
  264.    The `c-offsets-alist' variable controls the amount of indentation to
  265. give to each syntactic symbol.  Its value is an association list, and
  266. each element of the list has the form `(SYNTACTIC-SYMBOL . OFFSET)'.
  267. By changing the offsets for various syntactic symbols, you can
  268. customize indentation in fine detail.
  269.    Each offset value in `c-offsets-alist' can be an integer, a function
  270. or variable name, or one of the following symbols: `+', `-', `++', or
  271. `--', indicating positive or negative multiples of the variable
  272. `c-basic-offset'.  Thus, if you want to change the levels of
  273. indentation to be 3 spaces instead of 2 spaces, set `c-basic-offset' to
  274.    Using a function as the offset value provides the ultimate
  275. flexibility in customizing indentation.  The function is called with a
  276. single argument containing the `cons' of the syntactic symbol and the
  277. relative indent point.  The function should return an integer offset.
  278.    The command `C-c C-o' (`c-set-offset') is the easiest way to set
  279. offsets, both interactively or in your `~/.emacs' file.  First specify
  280. the syntactic symbol, then the offset you want.  *Note Syntactic
  281. Symbols::, for a list of valid syntactic symbols and their meanings.
  282.    The variable `c-offsets-alist-default' holds the default settings
  283. for the offsets of the syntactic symbols.  *Do not change this value!*
  284. File: emacs,  Node: Syntactic Symbols,  Next: Variables for C Indent,  Prev: Changing Indent Style,  Up: Custom C Indent
  285. Syntactic Symbols
  286. .................
  287.    Here is a table of valid syntactic symbols for C mode indentation,
  288. with their syntactic meanings.  Normally, most of these symbols are
  289. assigned offsets in `c-offsets-alist'.
  290. `string'
  291.      Inside a multi-line string.
  292.      Inside a multi-line C style block comment.
  293. `defun-open'
  294.      On a brace that opens a function definition.
  295. `defun-close'
  296.      On a brace that closes a function definition.
  297. `defun-block-intro'
  298.      In the first line in a top-level defun.
  299. `class-open'
  300.      On a brace that opens a class definition.
  301. `class-close'
  302.      On a brace that closes a class definition.
  303. `inline-open'
  304.      On a brace that opens an in-class inline method.
  305. `inline-close'
  306.      On a brace that closes an in-class inline method.
  307. `ansi-funcdecl-cont'
  308.      In the nether region between an ANSI function declaration and the
  309.      defun opening brace.
  310. `knr-argdecl-intro'
  311.      On the first line of a K&R C argument declaration.
  312. `knr-argdecl'
  313.      In one of the subsequent lines in a K&R C argument declaration.
  314. `topmost-intro'
  315.      On the first line in a topmost construct definition.
  316. `topmost-intro-cont'
  317.      On the topmost definition continuation lines.
  318. `member-init-intro'
  319.      On the first line in a member initialization list.
  320. `member-init-cont'
  321.      On one of the subsequent member initialization list lines.
  322. `inher-intro'
  323.      On the first line of a multiple inheritance list.
  324. `inher-cont'
  325.      On one of the subsequent multiple inheritance lines.
  326. `block-open'
  327.      On a statement block open brace.
  328. `block-close'
  329.      On a statement block close brace.
  330. `brace-list-open'
  331.      On the opening brace of an `enum' or `static' array list.
  332. `brace-list-close'
  333.      On the closing brace of an `enum' or `static' array list.
  334. `brace-list-intro'
  335.      On the first line in an `enum' or `static' array list.
  336. `brace-list-entry'
  337.      On one of the subsequent lines in an `enum' or `static' array list.
  338. `statement'
  339.      On an ordinary statement.
  340. `statement-cont'
  341.      On a continuation line of a statement.
  342. `statement-block-intro'
  343.      On the first line in a new statement block.
  344. `statement-case-intro'
  345.      On the first line in a `case' "block".
  346. `statement-case-open'
  347.      On the first line in a `case' block starting with brace.
  348. `substatement'
  349.      On the first line after an `if', `while', `for', `do', or `else'.
  350. `substatement-open'
  351.      On the brace that opens a substatement block.
  352. `case-label'
  353.      On a `case' or `default' label.
  354. `access-label'
  355.      On a C++ `private', `protected', or `public' access label.
  356. `label'
  357.      On any ordinary label.
  358. `do-while-closure'
  359.      On the `while' that ends a `do'-`while' construct.
  360. `else-clause'
  361.      On the `else' of an `if'-`else' construct.
  362. `comment-intro'
  363.      On a line containing only a comment introduction.
  364. `arglist-intro'
  365.      On the first line in an argument list.
  366. `arglist-cont'
  367.      On one of the subsequent argument list lines when no arguments
  368.      follow on the same line as the the arglist opening parenthesis.
  369. `arglist-cont-nonempty'
  370.      On one of the subsequent argument list lines when at least one
  371.      argument follows on the same line as the arglist opening
  372.      parenthesis.
  373. `arglist-close'
  374.      On the closing parenthesis of an argument list.
  375. `stream-op'
  376.      On one of the lines continuing a stream operator construct.
  377. `inclass'
  378.      On a construct which is nested inside a class definition.
  379. `cpp-macro'
  380.      On the start of a cpp macro.
  381. `friend'
  382.      On a C++ `friend' declaration.
  383. `objc-method-intro'
  384.      On the first line of an Objective-C method definition.
  385. `objc-method-args-cont'
  386.      On one of the lines continuing an Objective-C method definition.
  387. `objc-method-call-cont'
  388.      On one of the lines continuing an Objective-C method call.
  389. File: emacs,  Node: Variables for C Indent,  Next: C Indent Styles,  Prev: Syntactic Symbols,  Up: Custom C Indent
  390. Variables for C Indentation
  391. ...........................
  392.    This section describes additional variables which control the
  393. indentation behavior of C mode and related mode.
  394. `c-offsets-alist'
  395.      Association list of syntactic symbols and their indentation
  396.      offsets.  *Note Changing Indent Style::, for details.
  397. `c-offsets-alist-default'
  398.      Default settings for the offsets of the syntactic symbols.  *Note
  399.      Changing Indent Style::.
  400. `c-style-alist'
  401.      Variable for specifying styles of indentation; see below.
  402. `c-basic-offset'
  403.      Amount of basic offset used by `+' and `-' symbols in
  404.      `c-offsets-alist'.
  405. `c-recognize-knr-p'
  406.      If this variable is non-`nil', C mode and Objective C mode
  407.      recognize K&R constructs.  This variable is needed because of
  408.      ambiguities in C syntax that make recognition of K&R constructs
  409.      problematic and slow.  If you always use ANSI C prototype syntax,
  410.      set this variable to `nil' to speed up C indentation.
  411.      This variable is `nil' by default in C++ mode, and `t' by default
  412.      in C mode and Objective C mode.
  413. `c-special-indent-hook'
  414.      Hook for user-defined special indentation adjustments.  This hook
  415.      is called after a line is indented by C mode and related modes.
  416.    The variable `c-style-alist' specifies the predefined indentation
  417. styles.  Each element has form `(NAME VARIABLE-SETTING...)', where NAME
  418. is the name of the style.  Each VARIABLE-SETTING has the form `(VARIABLE
  419. . VALUE)'; VARIABLE is one of the customization variables used by C
  420. mode, and VALUE is the value for that variable when using the selected
  421. style.
  422.    When VARIABLE is `c-offsets-alist', that is a special case: VALUE is
  423. appended to the front of the value of `c-offsets-alist' instead of
  424. replacing that value outright.  Therefore, it is not necessary for
  425. VALUE to specify each and every syntactic symbol--only those for which
  426. the style differs from the default.
  427.    The indentation of lines containing only comments is also affected by
  428. the variable `c-comment-only-line-offset' (*note Comments in C::.).
  429. File: emacs,  Node: C Indent Styles,  Prev: Variables for C Indent,  Up: Custom C Indent
  430. C Indentation Styles
  431. ....................
  432.    A "C style" is a collection of indentation style customizations.
  433. Emacs comes with several predefined indentation styles for C code
  434. including `gnu', `k&r', `bsd', `stroustrup' `whitesmith', `ellemtel',
  435. and `cc-mode'.  The default style is `gnu'.
  436.    To choose the style you want, use the command `M-x c-set-style'.
  437. Specify a style name as an argument (case is not significant in C style
  438. names).  The chosen style only affects newly visited buffers, not those
  439. you are already editing.
  440.    To define a new C indentation style, call the function `c-add-style':
  441.      (c-add-style NAME VALUES USE-NOW)
  442. Here NAME is the name of the new style (a string), and VALUES is an
  443. alist whose elements have the form `(VARIABLE . VALUE)'.  The variables
  444. you specify should be among those documented in *Note Variables for C
  445. Indent::.
  446.    If USE-NOW is non-`nil', `c-add-style' switches to the new style
  447. after defining it.
  448. File: emacs,  Node: Matching,  Next: Comments,  Prev: Program Indent,  Up: Programs
  449. Automatic Display Of Matching Parentheses
  450. =========================================
  451.    The Emacs parenthesis-matching feature is designed to show
  452. automatically how parentheses match in the text.  Whenever you type a
  453. self-inserting character that is a closing delimiter, the cursor moves
  454. momentarily to the location of the matching opening delimiter, provided
  455. that is on the screen.  If it is not on the screen, some text near it is
  456. displayed in the echo area.  Either way, you can tell what grouping is
  457. being closed off.
  458.    In Lisp, automatic matching applies only to parentheses.  In C, it
  459. applies to braces and brackets too.  Emacs knows which characters to
  460. regard as matching delimiters based on the syntax table, which is set
  461. by the major mode.  *Note Syntax::.
  462.    If the opening delimiter and closing delimiter are mismatched--such
  463. as in `[x)'--a warning message is displayed in the echo area.  The
  464. correct matches are specified in the syntax table.
  465.    Three variables control parenthesis match display.
  466. `blink-matching-paren' turns the feature on or off; `nil' turns it off,
  467. but the default is `t' to turn match display on.
  468. `blink-matching-delay' says how many seconds to wait; the default is 1,
  469. but on some systems it is useful to specify a fraction of a second.
  470. `blink-matching-paren-distance' specifies how many characters back to
  471. search to find the matching opening delimiter.  If the match is not
  472. found in that far, scanning stops, and nothing is displayed.  This is
  473. to prevent scanning for the matching delimiter from wasting lots of
  474. time when there is no match.  The default is 12,000.
  475.    When using X Windows, you can request a more powerful kind of
  476. automatic parenthesis matching by loading the `paren' library.  To load
  477. it, type `M-x load-library RET paren RET'.  This library turns off the
  478. usual kind of matching parenthesis display and substitutes another:
  479. whenever point is after a close parenthesis, the close parenthesis and
  480. its matching open parenthesis are both highlighted; otherwise, if point
  481. is before an open parenthesis, the matching close parenthesis is
  482. highlighted.  (There is no need to highlight the open parenthesis after
  483. point because the cursor appears on top of that character.)
  484. File: emacs,  Node: Comments,  Next: Balanced Editing,  Prev: Matching,  Up: Programs
  485. Manipulating Comments
  486. =====================
  487.    Because comments are such an important part of programming, Emacs
  488. provides special commands for editing and inserting comments.
  489. * Menu:
  490. * Comment Commands::
  491. * Multi-Line Comments::
  492. * Options for Comments::
  493. File: emacs,  Node: Comment Commands,  Next: Multi-Line Comments,  Up: Comments
  494. Comment Commands
  495. ----------------
  496.    The comment commands insert, kill and align comments.
  497. `M-;'
  498.      Insert or align comment (`indent-for-comment').
  499. `C-x ;'
  500.      Set comment column (`set-comment-column').
  501. `C-u - C-x ;'
  502.      Kill comment on current line (`kill-comment').
  503. `M-LFD'
  504.      Like RET followed by inserting and aligning a comment
  505.      (`indent-new-comment-line').
  506. `M-x comment-region'
  507.      Add or remove comment delimiters on all the lines in the region.
  508.    The command that creates a comment is `M-;' (`indent-for-comment').
  509. If there is no comment already on the line, a new comment is created,
  510. aligned at a specific column called the "comment column".  The comment
  511. is created by inserting the string Emacs thinks comments should start
  512. with (the value of `comment-start'; see below).  Point is left after
  513. that string.  If the text of the line extends past the comment column,
  514. then the indentation is done to a suitable boundary (usually, at least
  515. one space is inserted).  If the major mode has specified a string to
  516. terminate comments, that is inserted after point, to keep the syntax
  517. valid.
  518.    `M-;' can also be used to align an existing comment.  If a line
  519. already contains the string that starts comments, then `M-;' just moves
  520. point after it and re-indents it to the conventional place.  Exception:
  521. comments starting in column 0 are not moved.
  522.    Some major modes have special rules for indenting certain kinds of
  523. comments in certain contexts.  For example, in Lisp code, comments which
  524. start with two semicolons are indented as if they were lines of code,
  525. instead of at the comment column.  Comments which start with three
  526. semicolons are supposed to start at the left margin.  Emacs understands
  527. these conventions by indenting a double-semicolon comment using TAB,
  528. and by not changing the indentation of a triple-semicolon comment at
  529.      ;; This function is just an example
  530.      ;;; Here either two or three semicolons are appropriate.
  531.      (defun foo (x)
  532.      ;;; And now, the first part of the function:
  533.        ;; The following line adds one.
  534.        (1+ x))           ; This line adds one.
  535.    In C code, a comment preceded on its line by nothing but whitespace
  536. is indented like a line of code.
  537.    Even when an existing comment is properly aligned, `M-;' is still
  538. useful for moving directly to the start of the comment.
  539.    `C-u - C-x ;' (`kill-comment') kills the comment on the current line,
  540. if there is one.  The indentation before the start of the comment is
  541. killed as well.  If there does not appear to be a comment in the line,
  542. nothing is done.  To reinsert the comment on another line, move to the
  543. end of that line, do `C-y', and then do `M-;' to realign it.  Note that
  544. `C-u - C-x ;' is not a distinct key; it is `C-x ;'
  545. (`set-comment-column') with a negative argument.  That command is
  546. programmed so that when it receives a negative argument it calls
  547. `kill-comment'.  However, `kill-comment' is a valid command which you
  548. could bind directly to a key if you wanted to.
  549. File: emacs,  Node: Multi-Line Comments,  Next: Options for Comments,  Prev: Comment Commands,  Up: Comments
  550. Multiple Lines of Comments
  551. --------------------------
  552.    If you are typing a comment and wish to continue it on another line,
  553. you can use the command `M-LFD' (`indent-new-comment-line').  This
  554. terminates the comment you are typing, creates a new blank line
  555. afterward, and begins a new comment indented under the old one.  When
  556. Auto Fill mode is on, going past the fill column while typing a comment
  557. causes the comment to be continued in just this fashion.  If point is
  558. not at the end of the line when `M-LFD' is typed, the text on the rest
  559. of the line becomes part of the new comment line.
  560.    To turn existing lines into comment lines, use the `M-x
  561. comment-region' command.  It adds comment delimiters to the lines that
  562. start in the region, thus commenting them out.  With a negative
  563. argument, it does the opposite--it deletes comment delimiters from the
  564. lines in the region.
  565.    With a positive argument, `comment-region' duplicates the last
  566. character of the comment start sequence it adds; the argument specifies
  567. how many copies of the character to insert.  Thus, in Lisp mode, `C-u 2
  568. M-x comment-region' adds `;;' to each line.  Duplicating the comment
  569. delimiter is a way of calling attention to the comment.  It can also
  570. affect how the comment is indented.  In Lisp, for proper indentation,
  571. you should use an argument of two, if between defuns, and three, if
  572. within a defun.
  573. File: emacs,  Node: Options for Comments,  Prev: Multi-Line Comments,  Up: Comments
  574. Options Controlling Comments
  575. ----------------------------
  576.    The comment column is stored in the variable `comment-column'.  You
  577. can set it to a number explicitly.  Alternatively, the command `C-x ;'
  578. (`set-comment-column') sets the comment column to the column point is
  579. at.  `C-u C-x ;' sets the comment column to match the last comment
  580. before point in the buffer, and then does a `M-;' to align the current
  581. line's comment under the previous one.  Note that `C-u - C-x ;' runs
  582. the function `kill-comment' as described above.
  583.    The variable `comment-column' is per-buffer: setting the variable in
  584. the normal fashion affects only the current buffer, but there is a
  585. default value which you can change with `setq-default'.  *Note
  586. Locals::.  Many major modes initialize this variable for the current
  587. buffer.
  588.    The comment commands recognize comments based on the regular
  589. expression that is the value of the variable `comment-start-skip'.
  590. Make sure this regexp does not match the null string.  It may match more
  591. than the comment starting delimiter in the strictest sense of the word;
  592. for example, in C mode the value of the variable is `"/\\*+ *"', which
  593. matches extra stars and spaces after the `/*' itself.  (Note that `\\'
  594. is needed in Lisp syntax to include a `\' in the string, which is
  595. needed to deny the first star its special meaning in regexp syntax.
  596. *Note Regexps::.)
  597.    When a comment command makes a new comment, it inserts the value of
  598. `comment-start' to begin it.  The value of `comment-end' is inserted
  599. after point, so that it will follow the text that you will insert into
  600. the comment.  In C mode, `comment-start' has the value `"/* "' and
  601. `comment-end' has the value `" */"'.
  602.    The variable `comment-multi-line' controls how `M-LFD'
  603. (`indent-new-comment-line') behaves when used inside a comment.  If
  604. `comment-multi-line' is `nil', as it normally is, then the comment on
  605. the starting line is terminated and a new comment is started on the new
  606. following line.  If `comment-multi-line' is not `nil', then the new
  607. following line is set up as part of the same comment that was found on
  608. the starting line.  This is done by not inserting a terminator on the
  609. old line, and not inserting a starter on the new line.  In languages
  610. where multi-line comments work, the choice of value for this variable
  611. is a matter of taste.
  612.    The variable `comment-indent-function' should contain a function
  613. that will be called to compute the indentation for a newly inserted
  614. comment or for aligning an existing comment.  It is set differently by
  615. various major modes.  The function is called with no arguments, but with
  616. point at the beginning of the comment, or at the end of a line if a new
  617. comment is to be inserted.  It should return the column in which the
  618. comment ought to start.  For example, in Lisp mode, the indent hook
  619. function bases its decision on how many semicolons begin an existing
  620. comment, and on the code in the preceding lines.
  621. File: emacs,  Node: Balanced Editing,  Next: Symbol Completion,  Prev: Comments,  Up: Programs
  622. Editing Without Unbalanced Parentheses
  623. ======================================
  624. `M-('
  625.      Put parentheses around next sexp(s) (`insert-parentheses').
  626. `M-)'
  627.      Move past next close parenthesis and re-indent
  628.      (`move-over-close-and-reindent').
  629.    The commands `M-(' (`insert-parentheses') and `M-)'
  630. (`move-over-close-and-reindent') are designed to facilitate a style of
  631. editing which keeps parentheses balanced at all times.  `M-(' inserts a
  632. pair of parentheses, either together as in `()', or, if given an
  633. argument, around the next several sexps.  It leaves point after the
  634. open parenthesis.  The command `M-)' moves past the close parenthesis,
  635. deleting any indentation preceding it (in this example there is none),
  636. and indenting with LFD after it.
  637.    For example, instead of typing `( F O O )', you can type `M-( F O
  638. O', which has the same effect except for leaving the cursor before the
  639. close parenthesis.
  640.    `M-(' may insert a space before the open parenthesis, depending on
  641. the syntax class of the preceding character.  Set
  642. `parens-dont-require-spaces' to a non-`nil' value if you wish to
  643. inhibit this.
  644. File: emacs,  Node: Symbol Completion,  Next: Documentation,  Prev: Balanced Editing,  Up: Programs
  645. Completion for Symbol Names
  646. ===========================
  647.    Usually completion happens in the minibuffer.  But one kind of
  648. completion is available in all buffers: completion for symbol names.
  649.    The character `M-TAB' runs a command to complete the partial symbol
  650. before point against the set of meaningful symbol names.  Any
  651. additional characters determined by the partial name are inserted at
  652. point.
  653.    If the partial name in the buffer has more than one possible
  654. completion and they have no additional characters in common, a list of
  655. all possible completions is displayed in another window.
  656.    There are two ways of determining the set of legitimate symbol names
  657. to complete against.  In most major modes, this uses a tags table
  658. (*note Tags::.); the legitimate symbol names are the tag names listed in
  659. the tags table file.  The command which implements this is
  660. `complete-tag'.
  661.    In Emacs-Lisp mode, the name space for completion normally consists
  662. of nontrivial symbols present in Emacs--those that have function
  663. definitions, values or properties.  However, if there is an
  664. open-parenthesis immediately before the beginning of the partial symbol,
  665. only symbols with function definitions are considered as completions.
  666. The command which implements this is `lisp-complete-symbol'.
  667.    In Text mode and related modes, `M-TAB' completes words based on the
  668. spell-checker's dictionary.  *Note Spelling::.
  669. File: emacs,  Node: Documentation,  Next: Change Log,  Prev: Symbol Completion,  Up: Programs
  670. Documentation Commands
  671. ======================
  672.    As you edit Lisp code to be run in Emacs, the commands `C-h f'
  673. (`describe-function') and `C-h v' (`describe-variable') can be used to
  674. print documentation of functions and variables that you want to call.
  675. These commands use the minibuffer to read the name of a function or
  676. variable to document, and display the documentation in a window.
  677.    For extra convenience, these commands provide default arguments
  678. based on the code in the neighborhood of point.  `C-h f' sets the
  679. default to the function called in the innermost list containing point.
  680. `C-h v' uses the symbol name around or adjacent to point as its default.
  681.    Documentation on operating system commands, library functions and
  682. system calls can be obtained with the `M-x manual-entry' command.  This
  683. reads a topic as an argument, and displays the "man page" on that
  684. topic.  `manual-entry' starts a background process that formats the
  685. manual page, by running the `man' program.  The result goes in a buffer
  686. named `*man TOPIC*'.  These buffers use a special major mode, Man mode,
  687. that facilitates scrolling and examining other manual pages.  For
  688. details, type `C-h m' while in a man page buffer.
  689.    For a long man page, setting the faces properly can take substantial
  690. time.  By default, Emacs uses faces in man pages if you are using X
  691. Windows.  You can turn off use of faces in man pages by setting the
  692. variable `Man-fontify-manpage-flag' to `nil'.
  693.    If you insert the text of a man page into an Emacs buffer in some
  694. other fashion, you can use the command `M-x Man-fontify-manpage' to
  695. perform the same conversions that `M-x manual-entry' does.
  696.    Eventually the GNU project hopes to replace most man pages with
  697. better-organized manuals that you can browse with Info.  *Note Misc
  698. Help::.  Since this process is only partially completed, it is still
  699. useful to read manual pages.
  700. File: emacs,  Node: Change Log,  Next: Tags,  Prev: Documentation,  Up: Programs
  701. Change Logs
  702. ===========
  703.    The Emacs command `C-x 4 a' adds a new entry to the change log file
  704. for the file you are editing (`add-change-log-entry-other-window').
  705.    A change log file contains a chronological record of when and why you
  706. have changed a program, consisting of a sequence of entries describing
  707. individual changes.  Normally it is kept in a file called `ChangeLog'
  708. in the same directory as the file you are editing, or one of its parent
  709. directories.  A single `ChangeLog' file can record changes for all the
  710. files in its directory and all its subdirectories.
  711.    A change log entry starts with a header line that contains your name,
  712. your email address (taken from the variable `user-mail-address'), and
  713. the current date and time.  Aside from these header lines, every line
  714. in the change log starts with a space or a tab.  The bulk of the entry
  715. consists of "items", each of which starts with a line starting with
  716. whitespace and a star.  Here are two entries, each with two items:
  717.      Wed May  5 14:11:45 1993  Richard Stallman  <rms@gnu.ai.mit.edu>
  718.      
  719.              * man.el: Rename symbols `man-*' to `Man-*'.
  720.              (manual-entry): Make prompt string clearer.
  721.      
  722.              * simple.el (blink-matching-paren-distance):
  723.              Change default to 12,000.
  724.      
  725.      Tue May  4 12:42:19 1993  Richard Stallman  <rms@gnu.ai.mit.edu>
  726.      
  727.              * vc.el (minor-mode-map-alist): Don't use it if it's void.
  728.              (vc-cancel-version): Doc fix.
  729.    One entry can describe several changes; each change should have its
  730. own item.  Normally there should be a blank line between items.  When
  731. items are related (parts of the same change, in different places), group
  732. them by leaving no blank line between them.  The second entry above
  733. contains two items grouped in this way.
  734.    `C-x 4 a' visits the change log file and creates a new entry unless
  735. the most recent entry is for today's date and your name.  It also
  736. creates a new item for the current file.  For many languages, it can
  737. even guess the name of the function or other object that was changed.
  738.    The change log file is visited in Change Log mode.  In this major
  739. mode, each bunch of grouped items counts as one paragraph, and each
  740. entry is considered a page.  This facilitates editing the entries.  LFD
  741. and auto-fill indent each new line like the previous line; this is
  742. convenient for entering the contents of an entry.
  743.    Version control systems are another way to keep track of changes in
  744. your program and keep a change log.  *Note Log Entries::.
  745. File: emacs,  Node: Tags,  Next: Emerge,  Prev: Change Log,  Up: Programs
  746. Tags Tables
  747. ===========
  748.    A "tags table" is a description of how a multi-file program is
  749. broken up into files.  It lists the names of the component files and the
  750. names and positions of the functions (or other named subunits) in each
  751. file.  Grouping the related files makes it possible to search or replace
  752. through all the files with one command.  Recording the function names
  753. and positions makes possible the `M-.'  command which finds the
  754. definition of a function by looking up which of the files it is in.
  755.    Tags tables are stored in files called "tags table files".  The
  756. conventional name for a tags table file is `TAGS'.
  757.    Each entry in the tags table records the name of one tag, the name
  758. of the file that the tag is defined in (implicitly), and the position
  759. in that file of the tag's definition.
  760.    Just what names from the described files are recorded in the tags
  761. table depends on the programming language of the described file.  They
  762. normally include all functions and subroutines, and may also include
  763. global variables, data types, and anything else convenient.  Each name
  764. recorded is called a "tag".
  765. * Menu:
  766. * Tag Syntax::        Tag syntax for various types of code and text files.
  767. * Create Tags Table::    Creating a tags table with `etags'.
  768. * Select Tags Table::    How to visit a tags table.
  769. * Find Tag::        Commands to find the definition of a specific tag.
  770. * Tags Search::        Using a tags table for searching and replacing.
  771. * List Tags::        Listing and finding tags defined in a file.
  772. File: emacs,  Node: Tag Syntax,  Next: Create Tags Table,  Up: Tags
  773. Source File Tag Syntax
  774. ----------------------
  775.    * In Lisp code, any function defined with `defun', any variable
  776.      defined with `defvar' or `defconst', and in general the first
  777.      argument of any expression that starts with `(def' in column zero,
  778.      is a tag.
  779.    * In Scheme code, tags include anything defined with `def' or with a
  780.      construct whose name starts with `def'.  They also include
  781.      variables set with `set!' at top level in the file.
  782.    * In C code, any C function or typedef is a tag, and so are
  783.      definitions of struct, union and enum.  Any `#define' is also a
  784.      tag, unless `--no-defines' is specified when the tags table is
  785.      constructed, which sometimes makes the tags file much smaller.  In
  786.      C++ code, member functions are also recognized.
  787.    * In Yacc or Bison input files, each rule defines as a tag the
  788.      nonterminal it constructs.  The portions of the file that contain
  789.      C code are parsed as C code.
  790.    * In Fortran code, functions and subroutines are tags.
  791.    * In Pascal code, the tags are the functions and procedures defined
  792.      in the file.
  793.    * In Perl code, the tags are the procedures defined by the `sub'
  794.      keyword.
  795.    * In Prolog code, a tag name appears at the left margin.
  796.    * In Erlang code, the tags are the functions, records, and macros
  797.      defined in the file.
  798.    * In assembler code, labels appearing at the beginning of a line,
  799.      followed by a colon, are tags.
  800.    * In LaTeX text, the argument of any of the commands `\chapter',
  801.      `\section', `\subsection', `\subsubsection', `\eqno', `\label',
  802.      `\ref', `\cite', `\bibitem', `\part', `\appendix', `\entry', or
  803.      `\index', is a tag.
  804.      Other commands can make tags as well, if you specify them in the
  805.      environment variable `TEXTAGS' before invoking `etags'.  The value
  806.      of this environment variable should be a colon-separated list of
  807.      commands names.  For example,
  808.           TEXTAGS="def:newcommand:newenvironment"
  809.           export TEXTAGS
  810.      specifies (using Bourne shell syntax) that the commands `\def',
  811.      `\newcommand' and `\newenvironment' also define tags.
  812.    * You can also generate tags based on regexp matching (*note Create
  813.      Tags Table::.) for any text file.
  814. File: emacs,  Node: Create Tags Table,  Next: Select Tags Table,  Prev: Tag Syntax,  Up: Tags
  815. Creating Tags Tables
  816. --------------------
  817.    The `etags' program is used to create a tags table file.  It knows
  818. the syntax of several languages, as described in *Note Tag Syntax::.
  819. Here is how to run `etags':
  820.      etags INPUTFILES...
  821. The `etags' program reads the specified files, and writes a tags table
  822. named `TAGS' in the current working directory.  `etags' recognizes the
  823. language used in an input file based on its file name and contents.
  824. You can specify the language with the `--language=NAME' option,
  825. described below.
  826.    If the tags table data become outdated due to changes in the files
  827. described in the table, the way to update the tags table is the same
  828. way it was made in the first place.  It is not necessary to do this
  829. often.
  830.    If the tags table fails to record a tag, or records it for the wrong
  831. file, then Emacs cannot possibly find its definition.  However, if the
  832. position recorded in the tags table becomes a little bit wrong (due to
  833. some editing in the file that the tag definition is in), the only
  834. consequence is a slight delay in finding the tag.  Even if the stored
  835. position is very wrong, Emacs will still find the tag, but it must
  836. search the entire file for it.
  837.    So you should update a tags table when you define new tags that you
  838. want to have listed, or when you move tag definitions from one file to
  839. another, or when changes become substantial.  Normally there is no need
  840. to update the tags table after each edit, or even every day.
  841.    One tags table can effectively include another.  Specify the included
  842. tags file name with the `--include=FILE' option when creating the file
  843. that is to include it.  The latter file then acts as if it contained
  844. all the files specified in the included file, as well as the files it
  845. directly contains.
  846.    If you specify the source files with relative file names when you run
  847. `etags', the tags file will contain file names relative to the
  848. directory where the tags file was initially written.  This way, you can
  849. move an entire directory tree containing both the tags file and the
  850. source files, and the tags file will still refer correctly to the source
  851. files.
  852.    If you specify absolute file names as arguments to `etags', then the
  853. tags file will contain absolute file names.  This way, the tags file
  854. will still refer to the same files even if you move it, as long as the
  855. source files remain in the same place.  Absolute file names start with
  856. `/', or with `DEVICE:/' on MS-DOS and Windows.
  857.    When you want to make a tags table from a great number of files, you
  858. may have problems listing them on the command line, because some systems
  859. have a limit on its length.  The simplest way to circumvent this limit
  860. is to tell `etags' to read the file names from its standard input, by
  861. typing a dash in place of the file names, like this:
  862.      find . -name "*.[chCH]" -print | etags -
  863.    Use the option `--language=NAME' to specify the language explicitly.
  864. You can intermix these options with file names; each one applies to
  865. the file names that follow it.  Specify `--language=auto' to tell
  866. `etags' to resume guessing the language from the file names and file
  867. contents.  Specify `--language=none' to turn off language-specific
  868. processing entirely; then `etags' recognizes tags by regexp matching
  869. alone.  `etags --help' prints the list of the languages `etags' knows,
  870. and the file name rules for guessing the language.
  871.    The `--regex' option provides a general way of recognizing tags
  872. based on regexp matching.  You can freely intermix it with file names.
  873. Each `--regex' option adds to the preceding ones, and applies only to
  874. the following files.  The syntax is:
  875.      --regex=/TAGREGEXP[/NAMEREGEXP]/
  876. where TAGREGEXP is used to match the lines to tag.  It is always
  877. anchored, that is, it behaves as if preceded by `^'.  If you want to
  878. account for indentation, just match any initial number of blanks by
  879. beginning your regular expression with `[ \t]*'.  In the regular
  880. expressions, `\' quotes the next character, and `\t' stands for the tab
  881. character.  Note that `etags' does not handle the other C escape
  882. sequences for special characters.
  883.    You should not match more characters with TAGREGEXP than that needed
  884. to recognize what you want to tag.  If the match is such that more
  885. characters than needed are unavoidably matched by TAGREGEXP, you may
  886. find useful to add a NAMEREGEXP, in order to narrow the tag scope.  You
  887. can find some examples below.
  888.    The `-R' option deletes all the regexps defined with `--regex'
  889. options.  It applies to the file names following it, as you can see
  890. from the following example:
  891.      etags --regex=/REG1/ voo.doo --regex=/REG2/ \
  892.          bar.ber -R --lang=lisp los.er
  893. Here `etags' chooses the parsing language for `voo.doo' and `bar.ber'
  894. according to their contents.  `etags' also uses REG1 to recognize
  895. additional tags in `voo.doo', and both REG1 and REG2 to recognize
  896. additional tags in `bar.ber'.  `etags' uses the Lisp tags rules, and no
  897. regexp matching, to recognize tags in `los.er'.
  898.    Here are some more examples.  The regexps are quoted to protect them
  899. from shell interpretation.
  900. Tag the `DEFVAR' macros in the emacs source files:
  901.      --regex='/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
  902. Tag VHDL files (this example is a single long line, broken here for
  903. formatting reasons):
  904.      --language=none
  905.      --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/'
  906.      --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
  907.      \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
  908. Tag Cobol files (every label starting in column seven):
  909.      --language=none --regex='/.......[a-zA-Z0-9-]+\./'
  910. Tag Postscript files (every label starting in column one):
  911.      --language=none --regex='#/[^ \t{]+#/'
  912. Tag TCL files (this last example shows the usage of a NAMEREGEXP):
  913.      --lang=none --regex='/proc[ \t]+\([^ \t]+\)/\1/'
  914.    For a list of the other available `etags' options, execute `etags
  915. --help'.
  916.